package com.zgm.ch05.aop.pointcutAdvisor.aspectJExpression._4_1_8;

import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

import com.zgm.ch05.aop.pointcutAdvisor._4_1_3.SimpleAdvice;

public class AspectJExpressionPointcutDemo {

	public static void main(String[] args) {
		SampleBean target = new SampleBean();
		AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
		pc.setExpression("execution(* com.zgm.ch05.aop.pointcutAdvisor.aspectJExpression._4_1_8..SampleBean.get*(..))");
		
		SampleBean proxy = getProxy(pc, target);
		proxy.getName();
		proxy.setName("新name");
		proxy.getHeight();
	}
	
	public static SampleBean getProxy(AspectJExpressionPointcut pc, SampleBean target) {
		Advisor advisor = new DefaultPointcutAdvisor(pc, new SimpleAfterAdvice());
		ProxyFactory pf = new ProxyFactory();
		pf.addAdvisor(advisor);
		pf.setTarget(target);
		
		return (SampleBean) pf.getProxy();
		
	}
}
